// Copyright 2009 Jan Hosang <jan.hosang@gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package gomake

import (
    "fmt"
    "os"
)


type CleanTarget struct {
    files []string
}

func (*CleanTarget) Changed() bool { return true }
func (*CleanTarget) Label() string { return "clean" }
func (*CleanTarget) Output() string { return "" }
func (*CleanTarget) Sources() []string { return nil }
func (*CleanTarget) Dependencies() []string { return nil }
func (*CleanTarget) Temporaries() []string { return nil }

func NewCleanTarget(pkgs *goPkgs) *CleanTarget {
    trg := new(CleanTarget)
    trg.files = pkgs.AllTemporaries()
    return trg
}

func (trg *CleanTarget) Build() bool {
    for _, file := range trg.files {
        fmt.Printf("delete %s\n", file)
        os.Remove(file)
    }
    return true
}

func (trg *CleanTarget) String() string {
    return "clean deletes temporary files\n"
}


type NukeTarget struct {
    files []string
}

func (*NukeTarget) Changed() bool { return true }
func (*NukeTarget) Label() string { return "nuke" }
func (*NukeTarget) Output() string { return "" }
func (*NukeTarget) Sources() []string { return nil }
func (*NukeTarget) Dependencies() []string { return []string{"clean"} }
func (*NukeTarget) Temporaries() []string { return nil }

func NewNukeTarget(pkgs *goPkgs) *NukeTarget {
    trg := new(NukeTarget)
    trg.files = pkgs.AllOutputs()
    return trg
}

func (trg *NukeTarget) Build() bool {
    for _, file := range trg.files {
        fmt.Printf("delete %s\n", file)
        os.Remove(file)
    }
    return true
}

func (trg *NukeTarget) String() string {
    return "nuke deletes output files of all targets\n"
}
